//logs.js
//var util = require('../../utils/util.js')
var user  = require('../../utils/user.js')
var app = getApp()
Page({
  data: {
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    array: {1: '有',2: '无'},
    pricetype: {'total_money': '¥','travel_coin': '旅行币'},
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    radioItems: null,
    op:null,
    hidden: false
  },
  orderinfoBtnSure:function(){
    wx.navigateTo({
      url: '/pages/list/ordersuccess',
      success: function(res){
        // success
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    })
  },
  formSubmit: function(e) {
    var that      = this
    var info = {
      'caravan_id':that.data.op.id,
      'take_car_date':that.data.op.sdate,
      'leave_car_date':that.data.op.edate,
      'take_car_area':e.detail.value.take_car_area,
      'rent_contact_id':e.detail.value.contactid,
      'leave_car_area':e.detail.value.leave_car_area,
      'caravan_user_id':e.detail.value.caravan_user_id
    }
    app.post('/wxapp/base/CreateOrder',{'orderinfo':info},function(res){
          if (res.data) {
              wx.requestPayment({
                 'timeStamp': '',
                 'nonceStr': '',
                 'package': '',
                 'signType': 'MD5',
                 'paySign': '',
                 'success':function(res){
                    wx.navigateTo({
                      url: '/pages/list/ordersuccess',
                    })
                 },
                 'fail':function(res){
                    wx.navigateTo({
                      url: '/pages/list/ordererror',
                    })
                 }
              })
          }
    })
  },
  onShow:function(options){
    if (user.checkLogin()==false) {
       wx.navigateTo({
        url: '/pages/login/login'
      })
    }
    options = this.data.op
    var that = this
    app.getJson('/wxapp/base/UserAllContacts',{},function(res){
      console.log(res.data)
      that.setData({
        radioItems: res.data
      })
    })
  },
  onLoad:function(options){
    this.setData({
      op:options
    })
    var caralltypes = wx.getStorageSync('$caralltypes')
    var that = this
    app.getJson('/wxapp/caravan/info',{'id':options.id},function(res){
      wx.setStorageSync('$campid', res.data.services)
      that.setData({
        caravaninfo: res.data,
        caralltypes:caralltypes,
        sdate:options.sdate,
        edate:options.edate
      })
    })
    var campid = wx.getStorageSync('$campid')
    app.getJson('/wxapp/base/campinfo',{'id':campid},function(res){
      that.setData({
        campinfo: res.data,
      })
    })
    app.getJson('/wxapp/base/orderprice',{'id':options.id,'sdate':options.sdate,'edate':options.edate},function(res){
      that.setData({
        orderprice: res.data,
      })
    })
  },
  radioChange: function(e) {
    var checked = e.detail.value
    var changed = {}
    for (var i = 0; i < this.data.radioItems.length; i ++) {
      if (checked.indexOf(this.data.radioItems[i].id) !== -1) {
        changed['radioItems['+i+'].checked'] = true
      } else {
        changed['radioItems['+i+'].checked'] = false
      }
    }
    this.setData(changed)
  },
  orderinfoAddBtn:function(e){
    //contype标记添加
    wx.navigateTo({
      url: '/pages/list/orderinfoadd?contype=1',
      success: function(res){
        // success
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    })
  }
})
